# encoding=utf-8

import requests

# 查看模块版本
c = requests.__version__
print(c)

# python解析的百度翻译
def fanyi():
    while True:
        context = input("请输入翻译的内容(退出q)：")

        if context in ['q', 'Q']:
            break
        else:
            url = 'http://fanyi.baidu.com/v2transapi/'
            data = {
                'from': 'en',
                'to': 'zh',
                'query': context,
                'transtype': 'translang',
                'simple_means_flag': '3',
            }
            headers = {
                'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.153 Safari/537.36 SE 2.X MetaSr 1.0'}
            response = requests.post(url, data, headers=headers)
            head = response.headers

            print(head['Content-Type'])
            print(response.json()['trans_result']['data'][0]['dst'])


fanyi()
